package com.nanbei.eduService.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nanbei.commonUntil.R;
import com.nanbei.eduService.entity.EduCourse;
import com.nanbei.eduService.entity.EduTeacher;
import com.nanbei.eduService.service.EduCourseService;
import com.nanbei.eduService.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduService/front")
@CrossOrigin  //解决跨域问题
public class UserFrontIndex {

    @Autowired
    private EduTeacherService eduTeacherService;

    @Autowired
    private EduCourseService eduCourseService;


    @GetMapping("/findCourseAndTeacher")
    public R findCourseAndTeacher(){
        QueryWrapper<EduTeacher> eduTeacherQueryWrapper = new QueryWrapper<>();
        eduTeacherQueryWrapper.orderByDesc("id");
        eduTeacherQueryWrapper.last(" limit 4");
        List<EduTeacher> teacherList = eduTeacherService.list(eduTeacherQueryWrapper);

        QueryWrapper<EduCourse> eduCourseQueryWrapper = new QueryWrapper<>();
        eduCourseQueryWrapper.orderByDesc("id");
        eduCourseQueryWrapper.last(" limit 8");
        List<EduCourse> eduCourseList = eduCourseService.list(eduCourseQueryWrapper);

        return R.ok().data("teacherList",teacherList).data("eduCourseList",eduCourseList);

    }
}
